<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.sinodata.bsm.common.vo.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>应用系统新增</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<%@ include file="../include/common.jsp"%>
		<%@ include file="../include/form.jsp"%>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/select/jquery.image.select.css"  />
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/select/jquery.image.select.min.js"></script>
		<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/select/jquery.multiselect.css" />
		<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/jquery-ui.css" />
		<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery/jquery-ui.min.js"></script>
	
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/select/jquery.multiselect.min.js"></script>
		<style type="text/css">
			.add_block {
				background-color: #ECF6FC; 
				width : 50%;
				margin:5px auto;
				min-width: 600px;
				width: 50%
			}
</style>
		<script type="text/javascript">
			$(document).ready(function(){
				$.formValidator.initConfig({
						formid:"resForm",
						onerror:function(msg){},
						onsuccess:function(){
							 $.ajax({
									type:'post',
									url:'app!save.action',
									data:$('#resForm').serialize(),
									global:false,
									async:false,
									cache:false,
									dataType:'json',
									success:function(data,textStatus){
											
										  window.location.assign('${pageContext.request.contextPath}/jsp/appview/viewdetail1.jsp?resid='+data.id);
									},
									error:function(){
										$.jBox.alert('服务器内部错误,请联系管理员','错误');
									}
 		   				   });
						  return false;
				}});
				
				$("#ip").formValidator({onshow:"请输入应用系统IP",oncorrect:"输入正确"}).inputValidator({min:1, onerror:"请输入应用系统IP"}).functionValidator({
		    		fun:function(val,elem){
		    			var v = $("#ip").val();
		        		if (!isIP(v)) {
							return "请输入应用系统IP"
						}
						return true;
					}
				});
				
				$("#name").formValidator({onshow:"请输入应用系统名称",onfocus:"应用系统名称最大长度为40"})
		          .inputValidator({min:1,onerror:"应用系统名称不能为空"})
		          .functionValidator({
		          	  fun:function(val,elem){
		          	     if(val.length>40){
		          	     	return "应用系统名称长度输入有误";
		          	     }
		          	     return true;
		          	  }
		         });
				$("#probeId").formValidator({onshow:"请选择采集器",onfocus:"采集器为必选项"})
				   .inputValidator({min:1,onerror: "采集器为必选项"})
				   .functionValidator({
				   		fun:function(val,elem){
				   			return true;
				   		}
				 });
			
				//显示probe状态
				$("#probeId").msDropDown().data("dd");
			/*	$('#ip').live('blur',function(){
					agreementValidate();
				});*/
				$('#resRelation').multiselect({
						noneSelectedText:'---请选择---',
					   selectedList: 2
					   
				});
			});
			
			
		
	
			//返回
		function back(){
			var backUrl = document.referrer;
			location.assign(backUrl);
		}
		</script>
	</head>

	<body>
		<h2 class="title-h2" style="margin-top:0; "><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>增加应用系统</h2>
		<form  name="resForm" id="resForm" >
			<div class="add_block">
				<input type="hidden" name="parentId" id="parentId" value="" />
				<input type="hidden" name="viewId" id="viewId" value="550" />
				<table class="table_eidt" id="restable">
					<tbody>
						<tr>
							<td class="td_left">
								<span class="span_alert">*</span> 资源类型
							</td>
							<td class="td_right">
								<input type="text" name="resTypeName" id="resTypeName" class="input_text " value="应用系统" disabled="disabled" />
								<input type="hidden" name="resTypeId" id="resTypeId" value="1105050000000" />
							</td>
						</tr>
						<tr>
							<td class="td_left">
								<span class="span_alert">*</span> 应用系统IP
							</td>
							<td class="td_right">
								<input type="text" name="ip" id="ip" class="input_text"
									maxlength="15" value="127.0.0.1"/>
								<span id="ipTip"></span>
							</td>
						</tr>
						<tr>
							<td class="td_left">
								<span class="span_alert">*</span> 应用系统名称
							</td>
							<td class="td_right">
								<input type="text" name="name" id="name" class="input_text" />
								<span id="nameTip"></span>
							</td>
						</tr>
						<tr>
							<td class="td_left">
								关联的应用系统
							</td>
							<td class="td_right">
								  <select id="resRelation" name="resRelation" multiple="multiple" size="1"  class="select" style="height:22px; text-align:center;" >
								 	<%
								 		List<Res> list = (List<Res>)request.getAttribute("appList");
								 		for(Res res : list){
								 		   out.println("<option value='"+res.getId()+"'>"+res.getName()+"</option>");
								 		}
								 	
								 	%>
								  </select>
							</td>
						</tr>
						<tr>
							<td class="td_left">
								<span class="span_alert">*</span> 采集器
							</td>
							<td class="td_right">
								<select id="probeId" name="probeId" class="select" style="width: 227px;">
									<option value="" title="">---- 请选择采集器 ----</option>
									<%
									    List<Probe> probes = (List<Probe>) request.getAttribute("probeList");
									    if (probes != null)
									        for (Probe p : probes) {
									            if (p.getStatus() == 3) {
									                out.println("<option value='" + p.getId() + "' title='/bsm/style/default/bsm/images/proberun.png' >" + p.getId() + "_" + p.getName() + "</option>");
									            } else {
									                out.println("<option value='" + p.getId() + "' title='/bsm/style/default/bsm/images/probestop.png' >" + p.getId() + "_" + p.getName() + "</option>");
									            }
									        }
									%>
								</select>
								<span id="probeIdTip"></span>
							</td>
						</tr>
						<tr>
							<td class="td_left">
								描述
							</td>
							<td class="td_right">
								<textarea class="input_textarea" name="desc" rows="3"
									onkeydown="this.value=this.value.substring(0,225)"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div  class="btn-div" >
    			<button type="submit" id ="saveBt" value="保存" class="btn-4" >保存</button>
    			<button type="button" onclick="back()" class="btn-4" >返回</button>
    	    </div>	
		</form>
	</body>
</html>
